package com.train.common.enums.impl;

import cn.hutool.core.util.ArrayUtil;
import com.train.common.enums.Enums;
import com.train.common.status.HttpStatus;

/**
 * 系统异常枚举
 */
public enum SysExceptionEnums implements Enums {

    EXP_RATE_LIMIT(HttpStatus.ERROR, "系统繁忙, 请稍后再试"),

    EXP_DEGRADE(HttpStatus.ERROR, "系统繁忙, 请稍后再试"),
    EXP_SERVER(HttpStatus.ERROR, "系统异常, 请联系管理员"),
    EXP_OBJECT_CONVERT(HttpStatus.ERROR, "对象类型转换异常"),
    EXP_LOGIN_USER(HttpStatus.UNAUTHORIZED, "用户登陆认证失效, 请重新登录"),
    EXP_LOGIN_REPEAT(HttpStatus.UNAUTHORIZED, "用户已登陆, 请勿重复登录"),
    EXP_TOKEN_INVALID(HttpStatus.UNAUTHORIZED, "无效认证,请重新登录"),
    EXP_METHOD_NOT_SUPPORT(HttpStatus.BAD_METHOD, "请求方式不支持"),
    EXP_OBJECT_IS_NULL(HttpStatus.ERROR, "对象实例为空"),
    EXP_FILE_NOT_EXISTS(HttpStatus.ERROR, "文件不存在"),
    EXP_METHOD_INVALID(HttpStatus.ERROR, "无效方法调用");

    private final Integer code;

    private final String message;

    SysExceptionEnums(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    @Override
    public Integer getCode() {
        return code;
    }

    @Override
    public String getMessage() {
        return message;
    }


    public static SysExceptionEnums getByCode(Integer code) {
        return ArrayUtil.firstMatch(item -> item.getCode().equals(code), values());
    }
}
